(function () {

    //获取显示页面数据 服务器分页
    var serverData = {};
    var serverTable;
    jQuery(document).ready(function () {

        serverTable = jQuery('#dataTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/news/getpage',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                    data: null,
                    defaultContent: ""//排序
                },
                {
                    data: null,
                    defaultContent: "",
                    render: function (data, type, full, meta) {

                        var id=data.id
                        var operate ='<input type="checkbox" class="checkchild">';
                        return operate;

                    }
                },
                {
                    data: 'title'
                },
                {
                    data: 'type'
                },
                {
                    data: 'content'
                },
                {
                    data: 'createTime',
                    render : function(data,
                                      type, full,
                                      meta) {
                        if (data) {
                            return moment(data).format("YYYY-MM-DD");
                        }
                    }
                },
                // {
                //     data: null,
                //     defaultContent: "",
                //     render: function (data, type, full, meta) {
                //         var operate ='<button type="button" class="btn btn-sm btn-info editBtn" title="编辑"><i class="fa fa-pencil"></i></button>'
                //             +'<button type="button" class="btn btn-sm btn-info delBtn" title="删除"><i class="fa fa-remove"></i></button>';
                //
                //         return operate;
                //
                //     }
                // }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }

                serverTable.off('click', 'tr');
                serverTable.on('click', 'tr', function (event) {
                    event = event || window.event;
                    var target = event.target || event.scrElement;
                    var data = serverTable.row(this).data();

                    if (target.className.indexOf('fa-remove') != -1 || target.className.indexOf('delBtn') != -1) {

                        deleteModule(data);
                    }

                    if (target.className.indexOf('fa-pencil') != -1 || target.className.indexOf('editBtn') != -1) {

                        editModule(data);
                    }

                    return;
                });
            }
        });


        //查询
        jQuery('.searchBtn').on('click',function(){
            serverData.key=jQuery('#keyword').val();
            serverTable.draw();
        })
        //撤销查询
        jQuery('.resetBtn').on("click",function()
        {
            jQuery('#keyword').val('');
            serverData.key ='';
            serverTable.draw();
        });
// 下载附件
        jQuery(".download").on('click', function() {
            var selects=getSelect("#dataTable",1);
            var newsId=selects[0].id;
            filedown(newsId, '公司信息附件',1);
        });

    });
})();